﻿using Less.Windows;
using Less.WebBrowserQuery;
using System;
using System.Security;
using System.Windows.Forms;
using System.Collections.Generic;
using Less.Text;

namespace Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            this.Width = 1100;
            this.Height = 768;

            this.StartPosition = FormStartPosition.CenterScreen;

            this.webBrowser1.ScriptErrorsSuppressed = true;

            this.webBrowser1.DocumentCompleted += WebBrowser1_DocumentCompleted;

            try
            {
                RegEdit.UpdateWebBrowserVersion();
            }
            catch (SecurityException)
            {
                MessageBox.Show(@"程序需要修改注册表，让 WebBrowser 使用最新的 IE 版本，请以管理员身份运行");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.Navigate("https://www.jd.com/");
        }

        private void WebBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            HtmlElement[] elements = this.webBrowser1.Query(".cate_menu_item a");

            List<string> list = new List<string>();

            foreach (HtmlElement i in elements)
            {
                list.Add(i.InnerText);
            }

            MessageBox.Show(list.Join("，"));

            this.Close();
        }
    }
}
